<?php
include("ib/connexion/Mysql.php");
include("ib/connexion/SQLRequest.php");
include("vo/value/ContactVO.php");
/**
 * Class Contact
 */ 
class IBService
{

 		function IBService()
 		{
 				$this->methodTable["getAllContact"]['access'] = 'remote';
       			$this->methodTable["getAllContact"]['description'] = 'Return the Contact list :)';	
 		}
	/**
	  * getAllContact
	  * @returns all contact in the database
	  */
	 public function getAllContact() 
	 {
       	$rest = array();
       
		$db = Mysql::getInstance( '127.0.0.1', 'ib', 'root', '' );
		$db->Open();
		
		$request = SQLRequest::getRequest( "contact" );
		$result = $db->Query( $request );
		
		/*
		$arr = array( );
		array_push( $arr, $db->FetchAssoc( $result ) );
		*/
		
        // on fait une boucle qui va faire un tour pour chaque enregistrement
		
		/* foreach( $arr as $data ) */
		while( $data = mysql_fetch_assoc( $result ) )
        {
            $id = $data['contact_id'];
            $name = $data['contact_name'];
            $surname = $data['contact_surname'];
	    $values = array("id"=>$id, "name"=>$name, "surname"=>$surname);
	    $contact = new ContactVO( $values );
            array_push($rest, $contact);
        }
        
		$db->Close();

        // on retourne le tableau
        return $rest;
	 }
}
?>
